// 编译器 MinGW
#include <iostream>
#include <windows.h>

using namespace std;

class Temp
{
public:
    Temp()
    {
        m_Temp = new int(10);
    }

    ~Temp()
    {
        if (m_Temp != nullptr)
        {
            delete m_Temp;
            m_Temp = nullptr;
        }
    }

    void getVal()
    {
        cout << "\x1b[32mtemp = " << *m_Temp << "\x1b[0m" << endl;
    }

    void setVal()
    {
        int temp;
        do
        {
            cout << "设置 <int>temp 的值:" << endl
                 << "> ";

            cin >> temp;

            if (cin.good())
            {
                *m_Temp = temp;
                getVal();
                break;
            }

        } while (1);
    }

    int *m_Temp;
};

int main()
{
    system("chcp 65001");
    system("cls");
    DWORD pid = GetCurrentProcessId();
    Temp temp;

    int flag = 0;

    while (1)
    {
        cout << "##################################" << endl
             << "进程id: " << pid << endl
             << "内存地址: " << temp.m_Temp << endl
             << "##################################" << endl;
        cout << "-----------------" << endl
             << "1. 获取temp值" << endl
             << "2. 设置temp值" << endl
             << "0. 退出程序" << endl
             << "-----------------" << endl
             << endl
             << "> ";

        cin >> flag;

        switch (flag)
        {
        case 1:
            temp.getVal();
            break;
        case 2:
            temp.setVal();
            break;

        default:
            goto exit;
            // return 0;
        }

        cout << endl
             << endl;
    }

exit:
    cout << "程序执行完成" << endl;
    system("pause");
    return 0;
}